package com.jweb.phone.web.controller;

import com.jweb.annotaion.JController;
import com.jweb.annotaion.JParam;
import com.jweb.core.JWebFilter;
import com.jweb.core.handle.Controller;
import com.jweb.plugin.jdbc.JdbcTemplate;

@JController("/news")
public class NewsController extends Controller {

	private JdbcTemplate jdbcTemplate = JWebFilter.getJdbctemplate();

	/**
	 * 获取新闻列表
	 * 
	 * @throws Exception
	 */
	public void getNewsList() {

	}

	public void ajaxNewsList(@JParam("begin") int begin) throws Exception {
		System.err.println("begin" + begin);
		toWriterJSON(jdbcTemplate.queryList("SELECT * FROM news ORDER BY id DESC LIMIT ?,? ", new Object[] { begin, begin + 20 }));
	}

	/**
	 * 查询新闻详情
	 * 
	 * @throws Exception
	 */
	public void show(@JParam("${1}") int id) throws Exception {
		System.err.println("id" + id);
		setAttr("bean", jdbcTemplate.query("SELECT * FROM news a,news_detail b  WHERE a.id=b.id AND a.id=?", new Object[] { id }));
	}
}
